package com.qingke.studentinfo.Controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qingke.studentinfo.Service.StudentService;
import com.qingke.studentinfo.pojo.Student;

public class FindStudentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private StudentService ss = new StudentService();
	
    public FindStudentServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String stuName = request.getParameter("stuName");
		if(stuName.equals("")) {
			stuName = null;
		}
		System.out.println(stuName);
		Student student = new Student();
		student.setStuName(stuName);
		List<Student> allStudents = ss.findAllStudents(student);
		request.setAttribute("allStudents", allStudents);
		//使用转发,设置要去的页面
		request.getRequestDispatcher("/searchStudent.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
